package com.peng.kslc;

import java.util.HashMap;
import java.util.Map;

/**
 * A1TwoSum
 *
 * @author lupeng
 * Created on 2022-07-17
 */
public class A1TwoSum {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> num2IndexMap = new HashMap<>();
        num2IndexMap.put(nums[0], 0);
        for (int i = 1; i < nums.length; i++) {
            if (num2IndexMap.get(target - nums[i]) != null) {
                return new int[]{i, num2IndexMap.get(target - nums[i])};
            } else {
                num2IndexMap.put(nums[i], i);
            }
        }
        return null;
    }

}
